package org.javaopenaccess.dao.classes;


import java.util.HashSet;
import java.util.Set;

import org.javaopenaccess.dao.AbstractDb4oSupportDao;
import org.javaopenaccess.model.ClassMetadata;
import org.javaopenaccess.model.InternalSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.db4o.ObjectSet;

public class Db4oClassDao extends AbstractDb4oSupportDao implements ClassDao {
	private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

	public Db4oClassDao(InternalSession session) {
		super(session);
	}
	public Db4oClassDao(){
		super();
	}

	@Override
	public void storeDynamicTypeObject(Object instance) {
		logger.info("storing custom type instance");
		getSession().store(instance);
	}
	
	public Set<Object> getObjectsByType(Class<?> clazz){
		logger.info("retriving custom type instance");
		//Move the data to a more generic java.util.Set
		ObjectSet<?> objects = null;
		objects = getSession().query(clazz);
		Set<Object> objectSet = new HashSet<Object>();
		objectSet.addAll(objects);
		return objectSet;
	}
	@Override
	public void storeClassMetadata(ClassMetadata metadata){
		getSession().store(metadata);
	}
	/**
	 * This doesn't work currently!!!Why?
	 */
	@Override
	public void storeClass(Class<?> clazz) {
		getSession().store(clazz);		
	}

}
